package com.jic.manager.controller.rest.sys;

import com.jic.common.base.vo.RestResult;
import com.jic.manager.entity.SysArticle;
import com.jic.manager.request.SysArticleRequest;
import com.jic.manager.response.SysArticleResponse;
import com.jic.manager.service.SysArticleService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Autor:zhaowei
* @Date: 2020/11/25 15:07
* @Description: 文章管理
*/
@RestController
@RequestMapping("/articleApi")
@Slf4j
public class ArticleApiController {

    @Autowired
    SysArticleService sysArticleService;

    /**
     * 根据分类查询文章列表
     */
    @PostMapping("/queryArticleListByCategory")
    @ApiOperation(value = " 根据分类查询文章列表 ")
    @ResponseBody
    public RestResult<List<SysArticleResponse>> queryArticleListByCategory (@RequestBody SysArticleRequest request){
        return RestResult.success(sysArticleService.queryArticleListByCategory(request));
    }

    /**
     * 查询文章详情
     */
    @PostMapping("/queryArticleDetail")
    @ApiOperation(value = " 查询文章详情 ")
    @ResponseBody
    public RestResult<SysArticleResponse> queryArticleDetail (@RequestBody SysArticleRequest request){
        SysArticle article = new SysArticle();
        BeanUtils.copyProperties(request, article);
        SysArticle result = sysArticleService.getByPrimaryKey(article);
        SysArticleResponse response = new SysArticleResponse();
        BeanUtils.copyProperties(result,response);
        return RestResult.success(response);
    }
}
